package cn.lzit.session.sy4;
import java.io.IOException;
        import javax.servlet.ServletException;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");

        String name = request.getParameter("username");
        if (name == null || name.isEmpty()) {
            response.sendRedirect("login.html");
            return;
        }

        // 将用户姓名存入Session
        request.getSession().setAttribute("customerName", name);
        String url = "<a href='food.html'>欢迎去食品柜台！</a>";
        response.getWriter().print("点击超链接，链接到food.html页面, 去采购食品。<br />" + url);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
